package ar.edu.itba.pod.Legajo47342.communication.handlers;

import java.rmi.RemoteException;

import ar.edu.itba.pod.Legajo47342.Node;
import ar.edu.itba.pod.simul.communication.MarketData;
import ar.edu.itba.pod.simul.communication.Message;
import ar.edu.itba.pod.simul.communication.MessageType;
import ar.edu.itba.pod.simul.communication.payload.NodeMarketDataPayload;
import ar.edu.itba.pod.simul.market.NodeMarketDataPayloadImpl;

public class NodeMarketDataRequestHandler implements Handler {

	private Node node;

	public NodeMarketDataRequestHandler(Node node) {
		super();
		this.node = node;
	}
	
	@Override
	public void handle(Message m) {
		MarketData data = node.getMarketManager().market().marketData();

		NodeMarketDataPayload pay = new NodeMarketDataPayloadImpl(data);
		
		Message mes = new Message(node.getNodeId(), System.currentTimeMillis(), MessageType.NODE_MARKET_DATA, pay);
		
		try {
			node.getManager().getGroupCommunication().send(mes, m.getNodeId());
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

}
